import 'package:json_annotation/json_annotation.dart';

part 'ring_sport_record.g.dart';

/// 戒指运动记录数据模型
@JsonSerializable()
class RingSportRecord {
  /// 戒指设备ID
  @JsonKey(name: 'deviceSn')
  final String deviceSn;

  /// 步数
  @JsonKey(name: 'steps')
  final int steps;

  /// 距离（米）
  @JsonKey(name: 'distance')
  final int distance;

  /// 卡路里
  @JsonKey(name: 'calories')
  final int calories;

  /// 运动时间（分钟）
  @JsonKey(name: 'sportTime')
  final int sportTime;

  const RingSportRecord({
    required this.deviceSn,
    required this.steps,
    required this.distance,
    required this.calories,
    required this.sportTime,
  });

  /// 从JSON创建实例
  factory RingSportRecord.fromJson(Map<String, dynamic> json) => 
      _$RingSportRecordFromJson(json);

  /// 转换为JSON
  Map<String, dynamic> toJson() => _$RingSportRecordToJson(this);

  /// 从步数数据创建运动记录
  factory RingSportRecord.fromStepsData({
    required String deviceSn,
    required int steps,
    required int distance,
    required int calories,
    int? time,
  }) {
    return RingSportRecord(
      deviceSn: deviceSn,
      steps: steps,
      distance: distance,
      calories: calories,
      sportTime: time ?? 0,
    );
  }

  @override
  String toString() {
    return 'RingSportRecord(deviceSn: $deviceSn, steps: $steps, distance: $distance, calories: $calories, sportTime: $sportTime)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is RingSportRecord &&
        other.deviceSn == deviceSn &&
        other.steps == steps &&
        other.distance == distance &&
        other.calories == calories &&
        other.sportTime == sportTime;
  }

  @override
  int get hashCode {
    return Object.hash(deviceSn, steps, distance, calories, sportTime);
  }
}
